package com.iflytek.education.controller;


import com.iflytek.common.annotation.Log;
import com.iflytek.common.core.controller.BaseController;
import com.iflytek.common.core.domain.AjaxResult;
import com.iflytek.common.enums.BusinessType;
import com.iflytek.common.utils.poi.ExcelUtil;
import com.iflytek.education.domain.EduSubject;
import com.iflytek.education.service.IEduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程类别Controller
 *
 * @author isahino
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/edu/subject" )
public class EduSubjectController extends BaseController {
    @Autowired
    private IEduSubjectService eduSubjectService;

    /**
     * 查询课程类别列表
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:list')" )
    @GetMapping("/list" )
    public AjaxResult list(EduSubject eduSubject) {
        List<EduSubject> list = eduSubjectService.selectEduSubjectList(eduSubject);
        return success(list);
    }

    /**
     * 导出课程类别列表
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:export')" )
    @Log(title = "课程类别" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, EduSubject eduSubject) {
        List<EduSubject> list = eduSubjectService.selectEduSubjectList(eduSubject);
        ExcelUtil<EduSubject> util = new ExcelUtil<EduSubject>(EduSubject.class);
        util.exportExcel(response, list, "课程类别数据" );
    }

    /**
     * 获取课程类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return success(eduSubjectService.selectEduSubjectById(id));
    }

    /**
     * 新增课程类别
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:add')" )
    @Log(title = "课程类别" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduSubject eduSubject) {
        return toAjax(eduSubjectService.insertEduSubject(eduSubject));
    }

    /**
     * 修改课程类别
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:edit')" )
    @Log(title = "课程类别" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduSubject eduSubject) {
        return toAjax(eduSubjectService.updateEduSubject(eduSubject));
    }

    /**
     * 删除课程类别
     */
    @PreAuthorize("@ss.hasPermi('edu:subject:remove')" )
    @Log(title = "课程类别" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}" )
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(eduSubjectService.deleteEduSubjectById(id));
    }
}
